var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
      ewm:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      this.getewm();
  },
  // 获取二维码
  getewm:function(){
    var shopid = wx.getStorageSync('shop_id');
    var that = this;
    var param = {
      url: "api/shop/getShopImg",
      data: {
        shop_id: shopid,
      },
      success: function (e) {
        console.log(e)
        that.setData({
          ewm: e.data.data.path,
        })
      },
    };
    app.post(param); 
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  saveit:function(){
    let that = this
    wx.getSetting({
      success(res) {
        //未授权 先授权 然后保存
        if (!res.authSetting['scope.writePhotosAlbum']) {
          wx.authorize({
            scope: 'scope.writePhotosAlbum',
            success(re) {
              that.saveToBlum();
            }
          })
        } else {
          //已授 直接调用保存到相册方法
          that.saveToBlum();
        }
      }
    })
  },

  saveToBlum: function () {
    var that = this;
    var ewm = that.data.ewm;
    wx.downloadFile({
      url: ewm,
      success: function (res) {
        wx.saveImageToPhotosAlbum({
          filePath: res.tempFilePath,
          success(result) {
            wx.showToast({
              title: '保存成功',
              icon:'none',
              duration:2000
            })
          }
        })
      },
      fail:function(){
        wx.showToast({
          title: '保存失败',
          icon: 'none',
          duration:2000
        })
      }
    })
  },

  goback:function(){
    wx.navigateBack({
      delta:1
    })
  }

})